﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using C.Entities;

namespace C.Unite
{
    /// <summary>
    /// 自定义流水号
    /// </summary>
    public class DFieldSN
    {
        /// <summary>
        /// 回访记录流水号
        /// </summary>
        /// <param name="snt">类型</param>
        /// <returns></returns>
        public static string SN(EnumData.DataSNEunm snt)
        {
            return SN(snt, true);
        }
        /// <summary>
        /// 回访记录流水号
        /// </summary>
        /// <param name="snt">类型</param>
        /// <param name="isshow">是否显示开头</param>
        /// <returns></returns>
        public static string SN(EnumData.DataSNEunm snt, bool isshow)
        {
            string getName = EnumHelper.GetEnumDesc(snt.GetType(), snt);
            List<string> ls = StringHelper.GetSubStringList(getName, '-');
            string Head = "";// ls[0];
            if (isshow)
                Head = ls[0];
            int maxid = 1;
            object ob = TbsDbSession.Default.FromSql("select max(id) from " + ls[1]).ToScalar();
            if (!string.IsNullOrEmpty(ob.ToString()))
                maxid = int.Parse(ob.ToString()) + 1;
            string sn = Head + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + maxid.ToString("00000");
            return sn;
        }
    }
}
